package ca.kooki.codesnippet.core;

import java.util.Date;


public class Action {
  
  //```````````````````````
  // MEMBER VARIABLES
  //```````````````````````
  
  private String _type;
  private String _description;
  private Date _when;
  private User _by;
  private boolean _success;
  
  //```````````````````````
  // CONSTRUCTOR
  //```````````````````````

  public Action(String type, String description)
  {
    init(type,description);
  }
  
  private void init(String type, String description)
  {
    _type = type;
    _description = description;
    _when = SystemDate.Now();
    _success = true;
    _by = User.ANNONYMOUS;
  }
  
  //```````````````````````
  // INTERFACE
  //```````````````````````
  
  public String getType()
  {
    return _type;
  }
  
  public String getDescription()
  {
    return _description;
  }
  
  public Date when()
  {
    return _when;
  }
  
  public void setSuccess(boolean wasSuccess)
  {
    _success = wasSuccess;
  }
  
  public User getUser()
  {
    return _by;
  }
  
  public void setUser(User user)
  {
    _by = user;
  }
  
  public void setDate(Date when)
  {
    _when = when;
  }
  
  public boolean getSuccess()
  {
    return _success;
  }
  
  public String getSuccessText()
  {
    return _success ? "true" : "false";
  }
  
  public String toString()
  {
    String failedFlag = _success ? "" : "[failed] ";
    return failedFlag + _type + ", " + _description + ", " + SystemDate.formatDate(_when);
  }
  
  public boolean equals(Object obj)
  {
    if (obj == null || !Action.class.equals(obj.getClass()))
    {
      return false;
    }
    
    Action compareTo = (Action)obj;
    
    if (!_type.equals(compareTo._type))
    {
      return false;
    }

    if (!_description.equals(compareTo._description))
    {
      return false;
    }

    if (!SystemDate.areSimilar(_when,compareTo._when))
    {
      return false;
    }

    if (_success != compareTo._success)
    {
      return false;
    }

    return true;
  }

    

}
